import { getEchoTextByTrueOrFalse } from '@/utils/bizUtils';
export const getBatchModifyColumnsFn = (data) => {
  let { selectMethods } = data;
  let columns = [
    {
      title: '供应商代码',
      key: 'supplyUuid',
    },
    {
      title: '供应商名称',
      render: (h, { row }) => {
        return (
          <span>{ row.supplyInfoDTO?.supplyName }</span>
        )
      }
    },
    {
      title: 'SKU编码',
      key: 'skuNo',
    },
    {
      title: '商品名称',
      render: (h, { row }) => {
        return (
          <span>{ row.supplyProductInfo?.productName }</span>
        )
      }
    },
    {
      title: '规格',
      render: (h, { row }) => {
        return (
          <span>{ row.supplyProductInfo?.specDetailStr }</span>
        )
      }
    },
    {
      title: '城市',
      key: 'saleCityName',
    },
    {
      title: '业务区域',
      key: 'saleAreaName',
    },
    {
      title: '供应商管理区域',
      render: (h, { row }) => {
        return (
          <span>{ row.supplyInfoDTO?.supplyManagerArea }</span>
        )
      }
    },
    {
      title: '商品管理区域',
      render: (h, { row }) => {
        return (
          <span>{ row.supplyProductInfo?.manageArea }</span>
        )
      }
    },
    {
      title: '供货状态',
      key: 'supplyGoodsState',
    },
    {
      title: '是否主供-原值',
      fixed: 'right',
      render: (h, { row }) => {
        return getEchoTextByTrueOrFalse({ h, val: row.isMainSupplyOld })
      }
    },
    {
      title: '是否主供-现值',
      fixed: 'right',
      render: (h, { row }) => {
        return (
          <div>
            { renderIsSupplyFn(h, row, selectMethods) }
          </div>
        )
      }
    },
    {
      title: '操作',
      key: 'action',
      fixed: 'right'
    }
  ]
  return columns;
}

const isSupplyOptions = [
  {
    value: '1',
    label: '是'
  },
  {
    value: '2',
    label: '否'
  },
]

const renderIsSupplyFn = (h, row, selectMethods) => {
  if (row.isMainSupply === '1') {
    return (
      <span>是</span>
    )
  }
  if (row.isMainSupply === '2') {
    return (
      <el-select
        value={ row.isMainSupply }
        placeholder="请选择"
        onChange={ (val) => { selectMethods({ row, val }); }}
      >
        {
          isSupplyOptions.map(item => {
            return (
              <el-option
                key={ item.value }
                label={ item.label }
                value={ item.value }
              />
            )
          })
        }
      </el-select>
    )
  }
}
